.PHONY: build test clean lint fmt vet benchmark

# Build variables
BINARY_NAME=smart-snapshotter
VERSION=$(shell git describe --tags --always --dirty)
COMMIT=$(shell git rev-parse --short HEAD)
DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"

# Default target
all: build

# Build the binary
build:
	go build $(LDFLAGS) -o $(BINARY_NAME) ./cmd/snapshotter

# Run tests
test:
	go test -v ./...

# Run tests with coverage
test-coverage:
	go test -v -coverprofile=coverage.txt -covermode=atomic ./...
	go tool cover -html=coverage.txt -o coverage.html

# Run linter
lint:
	golangci-lint run

# Format code
fmt:
	go fmt ./...

# Run go vet
vet:
	go vet ./...

# Clean build artifacts
clean:
	rm -f $(BINARY_NAME)
	rm -f coverage.txt coverage.html

# Download dependencies
deps:
	go mod download
	go mod tidy

# Run the application
run: build
	./$(BINARY_NAME)

# Development mode with hot reload (requires air)
dev:
	air

# Install development tools
install-tools:
	go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
	go install github.com/cosmtrek/air@latest

# Docker build
docker-build:
	docker build -t smart-snapshotter:$(VERSION) .

# Generate mocks (if needed)
generate:
	go generate ./...

# Run benchmarks
benchmark:
	go test -bench=. -benchmem ./...

# Run benchmarks with custom options
benchmark-full:
	go test -bench=. -benchmem -benchtime=10s -count=3 ./...